package cn.shen.edit.controller;


import cn.shen.common.util.WebResultUtil;
import cn.shen.common.vo.WebResult;
import cn.shen.dao.bo.VideoBo;
import cn.shen.dao.entity.Video;
import cn.shen.dao.mapper.VideoMapper;
import cn.shen.dao.service.VideoService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@CrossOrigin(origins = "*")
@RequestMapping("/video")
@Slf4j
public class VideoController {

    @Autowired
    VideoMapper videoMapper;



    @RequestMapping("/page")
    public WebResult<PageInfo<Video>> findVideoList(@RequestBody VideoBo videoBo){
//    public WebResult<String> findVideoList(@RequestBody VideoBo videoBo){
        log.info("分页查询视频资源");
        Page<Video> page = PageHelper.startPage(videoBo.getPageNum(),videoBo.getPageSize());
        List<Video> videoList = videoMapper.selectList(new LambdaQueryWrapper<Video>().select());
        PageInfo<Video> videoBoPageInfo = page.toPageInfo();
        videoBoPageInfo.setList(videoList);
        log.info("查询完毕");
        log.info("当前查询页码: {},当前查询每页数量: {}",videoBo.getPageNum(),videoBo.getPageSize());
        return WebResultUtil.genSuccessResult(videoBoPageInfo);

//        return WebResultUtil.genSuccessResult("videoBoPageInfo");

    }

    @PostMapping("/addVide")
    public WebResult addVideo(@RequestBody Video from){
        log.info("开始新增视频资源");
//        videoService.test1();

        return WebResultUtil.genSuccessResult();
    }



}
